<?php
/**
 *  💡 免责声明：本软件不得用于商业用途，仅做学习交流
 *  ⚠️ 权利声明：本软件由版权人提供产品技术支持
 *  📅 项目编号：NX2025-0135
 */
namespace App\Models;

use DateTimeInterface;
use Illuminate\Database\Eloquent\Factories\HasFactory;
use Illuminate\Database\Eloquent\Model;

class TradingHall extends Model
{
    use HasFactory;
    use \App\Traits\ModelTraits\LogsActivityTrait;

    protected $table = 'trading_halls';

    //protected $primaryKey='';
    //public $incrementing = false //使用非递增或者非数字的主键设置false
    //public $timestamps = false; //关闭自动时间维护
    //protected $fillable = ['']; //可被批量赋值
    protected $guarded = []; //不被批量赋值 空为全部可以赋值

    //protected $dates = ['deleted_at'];
    //protected $hidden = ['user_password'];
    protected $casts = [
        'created_at' => 'datetime:Y-m-d H:i:s',
        'updated_at' => 'datetime:Y-m-d H:i:s',
    ];

    public function user()
    {
        return $this->hasOne(User::class, 'id', 'user_id')->select(['id', 'name', 'profile']);
    }

    public function buyTrades()
    {
        return $this->hasMany(CreditTrade::class, 'buy_order_id', 'id')
            ->with(['sellTrades', 'sellUser']);
    }

    public function sellTrades()
    {
        return $this->hasOne(CreditTrade::class, 'sell_order_id', 'id')
            ->with(['buyTrades', 'buyUser']);
    }

    protected function serializeDate(DateTimeInterface $date)
    {
        return $date->format('Y-m-d H:i:s');
    }
}
